package com.ys.erp.stage_user_service.controller;

import com.ys.erp.framework.annotation.*;
import com.ys.erp.framework.bean.dto.StageEmpDTO;
import com.ys.erp.framework.response.PageDTO;
import com.ys.erp.stage_user_service.bean.condition.UserPulseCondition;
import com.ys.erp.stage_user_service.bean.vo.UserPulseRecordStatisticsVO;
import com.ys.erp.stage_user_service.bean.vo.UserPulseRecordVO;
import com.ys.erp.stage_user_service.service.UserPulseService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zjj
 * @date 2025/05/21 14:04
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/manage/user/pulse")
@Tag(name = "后台用户幺豆相关接口", description = "后台用户幺豆相关接口")
@ResponseResult
public class UserYsPulseController {

    private final UserPulseService userPulseService;


    @PostMapping("/pageUserPulseRecord")
    @Operation(summary = "分页用户幺豆明细", description = "分页用户幺豆明细")
    @CheckEmpLogin
    @CheckAdminPermissions(right = "ys_pulse_view")
    public PageDTO<UserPulseRecordVO> pageUserPulseRecord(@RequestBody @Valid UserPulseCondition.PageInPulseRecordCon con,
                                                          @StageLoginEmp StageEmpDTO empDto) {
        return userPulseService.pageUserPulseRecord(empDto, con);
    }

    @PostMapping("/pageUserPulseStatistics")
    @Operation(summary = "分页用户幺豆统计", description = "分页用户幺豆统计")
    @CheckEmpLogin
    @CheckAdminPermissions(right = "ys_pulse_view")
    public UserPulseRecordStatisticsVO pageUserPulseStatistics(@RequestBody UserPulseCondition.PageInPulseRecordCon con,
                                                               @StageLoginEmp StageEmpDTO empDto) {
        con.setCurrent(1);
        con.setSize(1000000);
        return userPulseService.pageUserPulseStatistics(empDto, con);
    }
    @PostMapping("/inUserPulse")
    @Operation(summary = "充值用户幺豆", description = "充值用户幺豆")
    @CheckEmpLogin
    @RedissonLock(key = "#con.userId")
    @CheckAdminPermissions(right = "ys_pulse_view")
    public void inUserPulse(@RequestBody @Valid UserPulseCondition.InOrOutUserPulseCon con,
                            @StageLoginEmp StageEmpDTO empDto) {
        userPulseService.inUserPulse(empDto, con);
    }

    @PostMapping("/outUserPulse")
    @Operation(summary = "扣除用户幺豆", description = "扣除用户幺豆")
    @CheckEmpLogin
    @RedissonLock(key = "#con.userId")
    @CheckAdminPermissions(right = "ys_pulse_view")
    public void outUserPulse(@RequestBody @Valid UserPulseCondition.InOrOutUserPulseCon con,
                            @StageLoginEmp StageEmpDTO empDto) {
        userPulseService.outUserPulse(empDto, con);
    }

}
